package com.zprmb.udzt;

import java.text.DecimalFormat;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zprmb.udzt.ll.BaseHelper;

public class ZT_Success extends BaseActivity {
	private TextView invest_money,firstinvest,tv_fund,tv_cur;;
	private ImageView img_back;
	private DecimalFormat df = new DecimalFormat("###");
	private DecimalFormat df2 = new DecimalFormat("###0.00");
	private Button btn_ok;
	private RelativeLayout rl_back;
	private TextView tv_customer;
	private LinearLayout li_info;
	private ImageView img_qq;
	private LinearLayout li_tiyan;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.zt_success);
		 BbtApplication.getInstance().addActvity(this);
		img_back=(ImageView)findViewById(R.id.img_back);
		invest_money=(TextView)findViewById(R.id.invest_money);
		btn_ok=(Button)findViewById(R.id.btn_ok);
		li_info=(LinearLayout)findViewById(R.id.li_info);
		firstinvest=(TextView)findViewById(R.id.first_invest);
		li_tiyan=(LinearLayout)findViewById(R.id.li_tiyan);
		img_qq=(ImageView)findViewById(R.id.join_qq_group);
		tv_fund=(TextView)findViewById(R.id.tv_fund);
		tv_cur=(TextView)findViewById(R.id.tv_cur);
		tv_customer=(TextView)findViewById(R.id.enterprise_tel);
		img_qq.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				joinQQGroup("dYKhVAU5hwpBBFGWW0PPRgOLDi9-xdcd");
			}
		});
		tv_customer.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				BaseHelper.showDialog2(ZT_Success.this, "拨号", "400-0101-016", 1);
			}
		});
		if(getIntent().getBooleanExtra("useCurrentAmountToInvest", false)){
			li_info.setVisibility(View.VISIBLE);
			tv_fund.setText("可用余额扣减"+df2.format(getIntent().getDoubleExtra("useFundAmount", 0)));
			tv_cur.setText("智投宝余额扣减"+df2.format(getIntent().getDoubleExtra("useCurrAmount", 0)));
			
		}
		if(!getIntent().getStringExtra("firstamount").equals("0")){

			Intent intent=new Intent(ZT_Success.this,First_Invest.class);
			intent.putExtra("firstamount", getIntent().getStringExtra("firstamount"));
			startActivity(intent);
			
		}else{
			
		}
		invest_money.setText("成功支付"+df.format(Double.parseDouble(getIntent().getStringExtra("money")))+"元");
		rl_back=(RelativeLayout)findViewById(R.id.rl_back);
		rl_back.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
//				setResult(1); 
//				finish();
				Intent intent=new Intent(ZT_Success.this,MainActivity.class);
				intent.putExtra("regist", 1);
				startActivity(intent);
			}
		});
		img_back.setOnClickListener(new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
//			setResult(1); 
//			finish();
			Intent intent=new Intent(ZT_Success.this,MainActivity.class);
			intent.putExtra("regist", 1);
			startActivity(intent);
		}
	});
	    btn_ok.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
			Intent intent=new Intent(ZT_Success.this,MainActivity.class);
			intent.putExtra("regist", 1);
			startActivity(intent);
			}
		});
	}
	public boolean joinQQGroup(String key) {  
	    Intent intent = new Intent();  
	    intent.setData(Uri.parse("mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26k%3D" + key));  
	   // 此Flag可根据具体产品需要自定义，如设置，则在加群界面按返回，返回手Q主界面，不设置，按返回会返回到呼起产品界面    //intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)  
	    try {  
	        startActivity(intent);  
	        return true;  
	    } catch (Exception e) {  
	        // 未安装手Q或安装的版本不支持  
	        return false;  
	    }  
	}
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
//		setResult(1); 
//		finish();
		Intent intent=new Intent(ZT_Success.this,MainActivity.class);
		intent.putExtra("regist", 1);
		startActivity(intent);
		return super.onKeyDown(keyCode, event);
	}
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		BbtApplication.getInstance().removeActvity(this);
	}
}
